import React, { useCallback } from 'react';
import { Radio } from 'antd';
import type { RadioChangeEvent } from 'antd';

const options = [5, 6, 7, 8].map((v) => ({ label: v.toString(), value: v }));

interface SerialDataBitsViewProps {
  value?: number;
  onChange?: (value: number) => void;
}

const SerialDataBitsView: React.FC<SerialDataBitsViewProps> = ({
  value,
  onChange,
}) => {
  const handleChange = useCallback(
    (e: RadioChangeEvent) => onChange?.(Number(e.target.value)),
    [onChange]
  );

  return (
    <Radio.Group
      value={value}
      onChange={handleChange}
      optionType="button"
      buttonStyle="solid"
      options={options}
    />
  );
};

export default SerialDataBitsView;
